home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubmalm.zip / squf.ub < prev    next >
Text File  |  1990-08-22  |  692b  |  20 lines

  1.    10   *Squf(N,&F)
  2.    20   ' Shanks square form factorization of N.  F is a factor.
  3.    30   ' Version using the numerator of the convergent.
  4.    40   ' Second of 3 May 1990.
  5.    50   local H1,H2=1,P,Q,Pp=0,Qq=1,Qqq=N,Te,A,R=0,K,I=0,Ii=0,Ta
  6.    60   K=isqrt(N):if not res then F=K:return endif:H1=K:A=K
  7.    70   '
  8.    80   ' Loop starts here.
  9.    90   inc Ii:if Ii>2000 then F=0:return endif
  10.   100   P=K-R:Q=Qqq+A*(Pp-P)
  11.   110   A=(P+K)\Q:R=res:inc I
  12.   120   Te=A*H1+H2:H2=H1:H1=Te
  13.   130   Pp=P:Qqq=Qq:Qq=Q
  14.   140   Te=isqrt(Q):Ta=res
  15.   150   if or{odd(I),Ta<>0} then 90
  16.   160   Te=H2-Te
  17.   170   F=gcd(Te,N)
  18.   180   if or{F=1,F=N} then 90
  19.   190   return ' End of subroutine Squf.
  20.